/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package submarines;
import java.util.Date;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import static java.util.concurrent.TimeUnit.*;
/**
 *
 * @author sshiran
 */
/*public class SessionTimeOut {
    int sum = 0;
    private final ScheduledExecutorService scheduler =
       Executors.newScheduledThreadPool(1);

    public void beepForAnHour() {
        final Runnable beeper = new Runnable() {
                //public void run() { System.out.println("beep"); }
                public void run() { sum++; }
            };
        Date executionDate = new Date();
        final ScheduledFuture<?> beeperHandle =
            scheduler.scheduleAtFixedRate(beeper, executionDate.getTime(), 10, SECONDS);
        scheduler.schedule(new Runnable() {
                public void run() { beeperHandle.cancel(true); }
            }, 60 * 60, SECONDS);
    }
}*/

import java.util.Date;

import java.util.Timer;

import java.util.TimerTask;

public class ClassExecutingTask {

    long delay = 10*1000; // delay in ms : 120 * 1000 ms = 120 sec.
    LoopTask task = new LoopTask();
    Timer timer = new Timer("TaskName");
    PlayerManager pM;
    
    public ClassExecutingTask(PlayerManager pManager) {
        pM = pManager;
    }

    public void start() {
        timer.cancel();
        timer = new Timer("TaskName");
        Date executionDate = new Date(); // no params = now
        timer.scheduleAtFixedRate(task, executionDate, delay);
    }

    private class LoopTask extends TimerTask {
        public void run() {
            pM.timeOut();
            //System.out.println("This message will print every 10 seconds.");
        }
    }
    
    public void cancel()
    {
        timer.cancel();
    }

   /* public static void main(String[] args) {
    ClassExecutingTask executingTask = new ClassExecutingTask();
    executingTask.start();
    }*/


}